package leetcode.秋招.去哪儿;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2021/10/13 15:37
 * @description：
 */
public class Main1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.nextLine().trim();
        char[] chars = str.toCharArray();
        ArrayList<Word> words = new ArrayList<>();
        HashMap<Character, Word> map = new HashMap<>();
        for (int i = 0; i < chars.length; i++) {
            char ch = chars[i];
            boolean isDown = true;
            if (ch < 'a') {
                ch += 32;
                isDown = false;
            }
            Word word = map.getOrDefault(ch, new Word());
            word.word = ch;
            if (isDown) {
                word.downNum++;
            } else {
                word.upNum++;
            }
            word.sum++;
            map.put(ch, word);
        }
        for(Map.Entry<Character, Word> entry : map.entrySet()) {
            words.add(entry.getValue());
        }
        words.sort((o1, o2) -> {
            if (o1.sum != o2.sum) {
                return o2.sum - o1.sum;
            } else {
                return o1.word - o2.word;
            }
        });
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < words.size(); i++) {
            Word word = words.get(i);
            char ch = word.word;
            int upNum = word.upNum;
            while (upNum > 0) {
                builder.append((char) (ch - 32));
                upNum--;
            }
            int downNum = word.downNum;
            while (downNum > 0) {
                builder.append(ch);
                downNum--;
            }
        }
        System.out.println(builder);
    }

    static class Word {
        public char word;
        public int upNum;
        public int downNum;
        public int sum;

        @Override
        public String toString() {
            return "Word{" +
                    "word=" + word +
                    ", upNum=" + upNum +
                    ", downNum=" + downNum +
                    ", sum=" + sum +
                    '}';
        }
    }
}
